<template>
    <el-dialog :model-value="auditDialogVisible" :destroy-on-close="true" :title="dialogTitle" width="450px" @close="emits('closeDialog')">
        <el-form ref="dialogFormRef" :model="auditForm" prop="country_code" :rules="rules">
            <el-input v-model="auditForm.id" type="text" hidden="hidden" />
            <el-form-item label="审核结果" :label-width="formLabelWidth" prop="review_status">
                <el-radio-group v-model="auditForm.review_status">
                    <el-radio key="1" label="1">通过</el-radio>
                    <el-radio key="2" label="2">拒绝</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="审核意见" :label-width="formLabelWidth" prop="review_reason">
                <el-input v-model="auditForm.review_reason" type="textarea" rows="3" />
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="emits('cancel')">取消</el-button>
                <el-button type="primary" @click="submit(auditForm)" :loading="btnLoading">提交</el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script setup>
import { ref } from "vue";

const dialogFormRef = ref(null);

defineProps({
    auditDialogVisible: {
        type: Boolean,
        default: false
    },
    auditForm: {
        type: Object,
        default: {
            id: "",
            review_status: "",
            review_reason: ""
        }
    },
    btnLoading: {
        type: Boolean,
        default: false
    },
    dialogTitle: {
        type: String,
        default: ""
    }
});
const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);

const formLabelWidth = "140px";
// 校验
const rules = {
    review_status: [{ required: true, message: "请选择审核结果", trigger: "change" }],
    review_reason: [{ required: true, message: "请输入审核意见", trigger: "blur" }],
};
// 提交
const submit = auditForm => {
    dialogFormRef.value
        .validate()
        .then(async () => {
            try {
                const param = Object.assign({}, {
                    id: auditForm.id,
                    review_status: auditForm.review_status,
                    review_reason: auditForm.review_reason
                });
                emits("submitForm", param);
            } catch (error) {
                console.log(error);
            }
        })
        .catch(error => {
            console.log(error);
        });
};
</script>
  